home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / bccapp.zip / DIALOG.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  3KB  |  160 lines

  1. /*
  2.  *
  3.  * Class Implementation for Popup menu system
  4.  *
  5.  * (C) 1990 Vision Software
  6.  *
  7.  * $Id: dialog.c 1.2001 91/04/25 15:08:00 pcalvin release $
  8.  *
  9.  * Comments:
  10.  *
  11.  * This class provides simple dialog box management.  Nothing spectacular,
  12.  * We basically provide services to ask a question and get certain responses
  13.  *
  14.  * Bugs:
  15.  *
  16.  * None documented
  17.  *
  18.  */
  19. #include <stdlib.h>
  20. #include <conio.h>
  21. #include <string.h>
  22. #include <ctype.h>
  23.  
  24. #include <stdhdr.h>
  25. #include <adl.h>
  26. #include <menu.h>
  27.  
  28. /*
  29.  * Derivative of POPUP().  We provide our own display and and keyboard
  30.  * routines..
  31.  */
  32. DIALOG::DIALOG(SZ sz,CENT centMax,PENT pent) : POPUP(rowNil,colNil,centMax,pent)
  33.     {
  34.     szLine = sz;
  35.     }
  36.  
  37. DIALOG::~DIALOG()
  38.     {
  39.     if (pcolTabs != Nil)
  40.         delete pcolTabs;
  41.     }
  42.  
  43. /*
  44.  *    We replace the original Redraw() so that we may present the message
  45.  */
  46. VOID DIALOG::Redraw()
  47.     {
  48.     POPUP::Redraw();
  49.  
  50.     wnd.SayAt(1,2,szLine);
  51.     }
  52.  
  53. /*
  54.  * Answers with the total width of all of the selection entries..
  55.  */
  56. CCH DIALOG::CchFromCentPent(CENT centMax,PENT pent)
  57.     {
  58.     CCH cch = 4;
  59.  
  60.     pcolTabs = new COL[centMax];
  61.     MemoryAssert(pcolTabs);
  62.     PointerAssert(pent);
  63.     /*
  64.      * Figure total width of Buttons when they are displayed as needed..
  65.      */
  66.     for (CENT cent = centNil; cent < centMax; cent++)
  67.         {
  68.         pcolTabs[cent] = cch;
  69.         cch += strlen(pent[cent].sz) + 2;
  70.         }
  71.  
  72.     return (cch);
  73.     }
  74.  
  75. /*
  76.  * Displays each entry..
  77.  */
  78. VOID DIALOG::Display(CENT cent,PENT pent,WINDOW &rwnd,BOOL fSelected)
  79.     {
  80.     PointerAssert(pcolTabs);
  81.     PointerAssert(pent);
  82.     PointerAssert(pent[cent].sz);
  83.  
  84.     COL col = dcolButtons + pcolTabs[cent];
  85.     CO coBack = fSelected ? coGreen : coCyan;
  86.     SZ sz = SzFromCentPent(cent,pent);
  87.     CCH cch = pent[cent].cchHotKey+1;
  88.  
  89.     rwnd.SayHot(3,col,sz,cch,coBlack,coBack);
  90.     }
  91.  
  92. /*
  93.  * For dialog boxes, TAB is used to move between selections.  Because
  94.  * of this, we overide the Up/Down keys.
  95.  */
  96. BOOL DIALOG::FHandleCd(CENT &rcent,CD cd,PENT pent,WINDOW &rwnd)
  97.     {
  98.     BOOL fContinue = fTrue;
  99.  
  100.     switch (cd)
  101.         {
  102.     case cdTab:
  103.         Display(rcent,pent,rwnd,fFalse);
  104.         rcent += 1;
  105.         if (rcent >= centMax)
  106.             rcent = centNil;
  107.         break;
  108.     case cdCursorUp:
  109.     case cdCursorDown:
  110.         break;
  111.     default:
  112.         fContinue = POPUP::FHandleCd(rcent,cd,pent,rwnd);
  113.         break;
  114.         }
  115.  
  116.     return (fContinue);
  117.     }
  118.  
  119. /*
  120.  * Provide POPUP() with the dimensions of the windows..
  121.  */
  122. COL DIALOG::ColLeftFromCentPent(CENT cent,PENT pent)
  123.     {
  124.     PointerAssert(szLine);
  125.  
  126.     CCH cchMessage = strlen(szLine);
  127.     CCH cchButtons = CchFromCentPent(cent,pent);
  128.  
  129.     if (cchMessage > cchButtons)
  130.         {
  131.         cchWidth = cchMessage;
  132.         dcolButtons = (cchMessage - cchButtons) >> 1;
  133.         }
  134.     else
  135.         {
  136.         cchWidth = cchButtons;
  137.         dcolButtons = 0;
  138.         }
  139.  
  140.     return ((colGlobalWindowRight - cchWidth) >> 1);
  141.     }
  142.  
  143. /*
  144.  *    Answers with the row to display the dialog on..
  145.  */
  146. ROW DIALOG::RowTopFromCentPent(CENT cent,PENT pent)
  147.     {
  148.     return (7);
  149.     }
  150.  
  151. COL DIALOG::CcolFromCentPent(CENT centMac,PENT pent)
  152.     {
  153.     return (cchWidth + 2);
  154.     }
  155.  
  156. ROW DIALOG::CrowFromCentPent(CENT centMac,PENT pent)
  157.     {
  158.     return (5);
  159.     }
  160.